package com.campus.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.entity.File.FileUpload;
import com.campus.entity.vo.File.FileUploadVO;
import com.campus.mapper.FileUploadMapper;
import com.campus.service.FileUploadService;
import com.campus.util.CopyPropertiesUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author Alaskaboo
* @description 针对表【t_file_upload】的数据库操作Service实现
* @createDate 2022-11-09 23:21:58
*/
@Service
public class FileUploadServiceImpl extends ServiceImpl<FileUploadMapper, FileUpload>
    implements FileUploadService{

    @Override
    public IPage<FileUploadVO> getFileUploadPage(Page<FileUpload> page, FileUpload fileUpload) {
        QueryWrapper<FileUpload> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(fileUpload.getRemark())) {
            queryWrapper.like("remark", fileUpload.getRemark());
        }
        if (!StringUtils.isEmpty(fileUpload.getFileType())) {
            queryWrapper.like("file_type", fileUpload.getFileType());
        }
        queryWrapper.orderByAsc("id");
        List<FileUpload> fileUploadList = baseMapper.selectList(queryWrapper);
        List<FileUploadVO> collect = fileUploadList.stream().map(fileUpload1 -> CopyPropertiesUtils.copyProperties(fileUpload1, FileUploadVO.class)).collect(Collectors.toList());
        Page<FileUpload> page1 = baseMapper.selectPage(page, queryWrapper);
        Page<FileUploadVO> resPage = new Page<>();
        BeanUtil.copyProperties(page1,resPage);
        return resPage.setRecords(collect);
    }
}




